import requests
import json

# 本地服务器地址和端口
BASE_URL = "http://127.0.0.1:5000/generate_code"

# 测试请求数据
test_data = {
    "query": "20以内的不进位加法练习",
    "model": "DeepSeek"  # 或 "Zhipu"
}

def test_generate_code():
    try:
        # 发送 POST 请求
        response = requests.post(BASE_URL, json=test_data)
        
        # 检查响应状态码
        if response.status_code == 200:
            # 输出成功的结果
            result = response.json()
            print("测试成功：")
            print(json.dumps(result, indent=2, ensure_ascii=False))
        else:
            # 输出失败的结果
            print(f"测试失败，状态码：{response.status_code}")
            print(response.text)
    except Exception as e:
        print(f"测试时发生错误：{e}")

# 运行测试
if __name__ == "__main__":
    test_generate_code()
